<?php

class Application_Model_DbTable_Record extends Zend_Db_Table_Abstract
{


    protected $_name = 'expediente';

     public function findRecord($placa,$start_date,$end_date)
    {

       
        try{
              $start_date_formatted = date('Y-m-d', strtotime($start_date)).' 00:00:00';          
              $end_date_formatted = date('Y-m-d', strtotime($end_date)).' 00:00:00';


              if(empty($placa)){
                  

                $row = $this->fetchall($this->select()
                  ->where('fecha >= ?', $start_date_formatted)
                  ->where('fecha <= ?', $end_date_formatted)
                  ->where('tipo = ?', 'R')
                 );
          
               }else{
                  $row = $this->fetchall($this->select()
                  ->where('placa = ?', $placa)
                  ->where('fecha >= ?', $start_date_formatted)
                  ->where('fecha <= ?', $end_date_formatted)
                  ->where('tipo = ?', 'R')
                 );


               }
           
          
            if ($row) {
              
                 return $row->toArray();
                 
            }
            else{
               
                return $row;
                
            }       
        }catch(Zend_Exception $e){
            throw $e;
            echo  $e;
        }
    }
     public function findRecordProforma()
    {

       
        try{
            
                  $row = $this->fetchall(
                    $this->select()
                ->where('tipo = ?', 'P')
                 );

            if ($row) {
              
                 return $row->toArray();
                 
            }
            else{
               
                return $row;
                
            }       
        }catch(Zend_Exception $e){
            throw $e;
            echo  $e;
        }
    }
    public function addRecord($placa, $fecha,$observaciones,$tipo,$TotalServicio,$TotalRepueto)
    {
       
        $start_date_formatted = date('Y-m-d', strtotime($fecha)).' 00:00:00'; 
        $data = array(
            'placa' => $placa,
            'fecha' => $start_date_formatted,
            'observaciones' => $observaciones,
            'tipo' => $tipo,
             'totalServicio' => $TotalServicio,
            'totalRepuesto' => $TotalRepueto,
        );
        echo $start_date_formatted;
        //$this->insert($data);
    }
    
    public function deleteRecord($placa,$fecha)
    {
        try{    
             $this->delete()
              ->where('placa = ?', $placa)
              ->where('fecha = ?', $fecha);
        }catch(Zend_Exception $e){
            throw $e;
        }
    }

    

     public function getRecord($placa)
    {


        $row = $this->fetchRow('placa = ' . $placa);
        if (!$row) {
            throw new Exception("Could not find row $placa");
        }
        return $row->toArray();

    }




}